//
//  DJSwitchTableViewCell.m
//  DualJoy
//
//  Created by lijunge on 2019/11/14.
//  Copyright © 2019 lijunge. All rights reserved.
//

#import "DJSwitchTableViewCell.h"
#import "DJConstant.h"
#import <Masonry.h>

@implementation DJSwitchTableViewCell

+ (DJSwitchTableViewCell *)switchTableViewCellWithTableView:(UITableView *)tableView {
    
    DJSwitchTableViewCell *cell = [[DJSwitchTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        [self configSubViews];
    }
    return self;
}

- (void)configSubViews {
    
    [self addSubview:self.leftImgView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.detailSwitch];
    
    [self.leftImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(20);
        make.width.height.mas_equalTo(20);
        make.centerY.equalTo(self);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.leftImgView.mas_right).offset(16);
        make.height.mas_equalTo(30);
        make.centerY.equalTo(self);
    }];
    
    [self.detailSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-20);
        make.height.mas_equalTo(31);
        make.centerY.equalTo(self);
    }];
}

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

#pragma mark -

- (UIImageView *)leftImgView {
    if (_leftImgView == nil) {
        UIImageView *tmpImgView = [[UIImageView alloc] init];
        tmpImgView.backgroundColor = kVCBackColor;
        _leftImgView = tmpImgView;
    }
    return _leftImgView;
}

- (UILabel *)titleLabel {
    if (_titleLabel == nil) {
        UILabel *tmpLabel = [[UILabel alloc] init];
        tmpLabel.text = @"1234";
        tmpLabel.font = [UIFont systemFontOfSize:16];
        tmpLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel = tmpLabel;
    }
    return _titleLabel;
}

- (UISwitch *)detailSwitch {
    if (_detailSwitch == nil) {
        UISwitch *tmpSwitch = [[UISwitch alloc] init];
        tmpSwitch.on = YES;
        _detailSwitch = tmpSwitch;
    }
    return _detailSwitch;
    
}

@end
